import {Menu, Dropdown, Avatar} from 'antd';
import React from 'react';
import reqwest from 'reqwest';

class UserAvatar extends React.Component {
    handleClick = ({key}) => {
        if (key === '1') {
            console.log('click logout');
            reqwest({
                url: '/api/logout',
                method: 'post',
                success: (res) => {
                    if (res.error === '') {
                        this.props.handleLogout(res);
                    }
                }
            })
        }
    };

    render() {
        const menu = (
            <Menu onClick={this.handleClick}>
                <Menu.Item key="1">注销</Menu.Item>
            </Menu>
        );
        return (
            <Avatar>
                <Dropdown overlay={menu}>
                    <a className="ant-dropdown-link" href="">
                        {this.props.name}
                    </a>
                </Dropdown>
            </Avatar>
        )
    }
}

export default UserAvatar;